<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>
<body>
  <script src="../dev/vendors/vue.js"></script>
  <div id="app">
    <keep-alive>
      <components v-bind:is="currentView"></components>
    </keep-alive>
    <button v-on:click="goHome">Home</button>
    <button v-on:click="goPosts">Posts</button>
    <button v-on:click="goArchive">Archive</button>
  </div>
  <script>
    var vm = new Vue({
      el: '#app',
      data: {
        currentView: 'home'
      },
      components: {
        home: {
          template: '<div>HOME</div>'
        },
        posts: { 
          template: '<div>POSTS</div>'
         },
        archive: { 
          template: '<div>ARCHIVE</div>'
         }
      },
      methods: {
        goHome: function () {
          this.currentView = 'home'
        },
        goPosts: function () {
          this.currentView = 'posts'
        },
        goArchive: function () {
          this.currentView = 'archive'
        },
      }
    })
  </script>
</body>
</html>